﻿using Business.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Presenters.WPF
{
    public class SearchSubjectPresenter
    {
        public ISearchSubject view { get; set; }


        public SearchSubjectPresenter(ISearchSubject view)
        {
            this.view = view;            
        }

        public void SearchSubjectRealTime()
        {
            if (this.view.realTimeSearch == true)
            {
                SearchSubject();
            }
        }

        public void SearchSubject()
        {
            if (this.view.isSearchByName == true)
            {
                SearchByName();
            }

            if (this.view.isSearchByCode == true)
            {
                SearchByCode();
            }

            if (this.view.isSearchByAcronym == true)
            {
                SearchByAcronym();
            }
        }

        public void SearchByName()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.results = ssn.SearchByName(this.view.searchFilter, this.view.isOnlyActive);            
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SearchByAcronym()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.results = ssn.SearchByAcronym(this.view.searchFilter, this.view.isOnlyActive);
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }

        public void SearchByCode()
        {
            try
            {
                SearchSubjectManager ssn = new SearchSubjectManager();
                this.view.results = ssn.SearchByCode(this.view.searchFilter, this.view.isOnlyActive);
            }
            catch (Exception ex)
            {
                this.view.message = "Error -> " + ex.Message;
            }
        }


    }
}
